{  Statement: http://acmp.ru/?main=task&id_task=496
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n,ans,k:longint;
    a:array[0..1010] of longint;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
fillchar(a,sizeof(a),0);
read(n);
for i := 1 to n do begin
    read(k);
    inc(a[i], k);
    if i = 1 then begin
        inc(a[2], k);
        inc(a[n], k);
    end else
    if i = n then begin
        inc(a[n - 1], k);
        inc(a[1], k);
    end else begin
        inc(a[i - 1], k);
        inc(a[i + 1], k);
    end;
end;
ans := a[1];
for i := 2 to n do
    ans := max(ans, a[i]);
write(ans);
end.
